using System.Text.RegularExpressions;

namespace common
{
    public class StringHelper
    {
        public static string DeleteRegexString(string strBiaodashi, string strIn)
        {
            Regex r = new Regex(strBiaodashi);
            strIn = r.Replace(strIn, new MatchEvaluator(CapText));

            return strIn;
        }

        private static string CapText(Match m)
        {
            return "";
        }

        public static string GetRegexString(string strBiaodashi, string strSrc)
        {
            Regex r = new Regex(strBiaodashi);
            Match m = r.Match(strSrc);
            string s = "";

            if (m.Success)
            {
                s = m.Value.ToString();
                //m = m.NextMatch();
            }

            return s;
        }

        public static string GetMidRegexString(string strBiaodashiStart, string strBiaodashiEnd, string strSrc)
        {
            //int intStart = strSrc.IndexOf(strBiaodashiStart);
            //int intEnd = strSrc.IndexOf(strBiaodashiEnd);
            string strStart = GetRegexString(strBiaodashiStart, strSrc);
            string strEnd = GetRegexString(strBiaodashiEnd, strSrc);

            int intStart = strSrc.IndexOf(strStart);
            int intEnd = strSrc.IndexOf(strEnd);

            string strResult = "";
            strResult = strSrc.Substring(intStart + strBiaodashiStart.Length, intEnd - intStart - strBiaodashiStart.Length);
            return strResult;
        }

        public static string GetMidString(string strBiaodashiStart, string strBiaodashiEnd, string strSrc)
        {
            int intStart = strSrc.IndexOf(strBiaodashiStart);
            int intEnd = strSrc.IndexOf(strBiaodashiEnd);

            string strResult = "";
            strResult = strSrc.Substring(intStart + strBiaodashiStart.Length, intEnd - intStart - strBiaodashiStart.Length);
            return strResult;
        }
    }
}